/**
 * Created by Administrator on 2018/11/14.
 */
//初始化表格数据
$CertusJsonAjax.ajax("purchase/agreementInfoByProcId", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    if (res.data) {

        $$scope.agreementStep = {}
        $$scope.agreementStep.agreementCode = res.data.agreement.agreementCode;
        $$scope.agreementStep.processInstanceId = $CertusJsonAjax.getProInstanceId();
        $$scope.agreementStep.stepInstanceId = $CertusJsonAjax.getStepInstanceId();
        //请购单 数据

        var pltlogOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '请购清单',
            datas: res.data.buyingItem,
            columns: pltlogColumns,
            gridContainer: 'purchaselistContainer',
            toolbarContainer: 'purchaselistToolBarContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        var pltlogGrid = $.fn.dlshouwen.grid.init(pltlogOption);
        pltlogGrid.load();

        $$scope.agreement = res.data.agreement;

        $$scope.processs = res.data.processs;

    }
})

$$scope.downloadAgreement = function(){
    $CertusFormAjax.download("downloadFile", "fileId=" + eval("("+$$scope.agreement.filePath+")").fileId);
}

$$scope.agreementShutdown = function(){

}

$$scope.getsssbbb = function(bb){
    if(bb == "starting"){
        return "正在进行中";
    }else if(bb == "denied"){
        return "否决";
    }else if(bb == "sentback"){
        return "被退";
    }else if(bb == "others"){
        return "关闭";
    }else if(bb == "completed"){
         return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
    return "待办";
}

$$scope.agreementAgree = function(){
    $CertusJsonAjax.ajax("purchase/commitAgreement",$$scope.agreementStep,function(res){
        if(res.data == "success"){
            findBacklogPerson($CertusFormAjax,$CertusJsonAjax.getStepInstanceId());
            history.back();
        }
    })
}

$CertusJsonAjax.ajax("queryPurchaseAgreementProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processCCBXTrace = res.data;
})